const {
	Controller
} = require('uni-cloud-router')
const uniID = require('uni-id')
const dbHelper = require('db-helper')
module.exports = class StoreController extends Controller {
	
	async getStoreList() {
		let {
			keyword,
			pageNum,
			pageSize
		} = this.ctx.data
		try{
			let page = await this.service.store.getStoreList({
				keyword,
				pageNum,
				pageSize
			})
			return {
				code: 200,
				result: page
			}
		}catch(e){
			return {
				code: 500,
				msg: e.message
			}
		}
	}
	
	async getShorcutMenuList() {
		let {
			pageNum,
			pageSize,
			city,
		} = this.ctx.data
		try{
			let page = await this.service.store.getShorcutMenuList({
				pageNum,
				pageSize,
				city
			})
			return {
				code: 200,
				result: page
			}
		}catch(e){
			console.error(e)
			return {
				code: 500,
				msg: e.message
			}
		}
	}
  
  // 打开门禁
  async openDoor() {
    let { sn } = this.ctx.data
    
    if (!sn) return { code: 500, msg: '未绑定门禁设备' }
    
    return await this.service.store.openDoor(sn)
  }
}
